<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div>哈哈</div>
    <script>
        var box = document.querySelector("div");

        // console.log(box.style.width); // 行内

        // var res = window.getComputedStyle(box, null).width;
        var res = window.getComputedStyle(box, null).backgroundColor;
        console.log(res);
    </script>
</body>

</html>